using Plugins.FormicArch.Core;
using UnityEngine;
using UnityEngine.Profiling;

public class GameEventTest : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        //二次封装 方便调用
        FAEventManager.Register<int, string, Data, MyStruct>(PubliceEventType.Run, Run);
        FAEventManager.Trigger(PubliceEventType.Run, 2, "test", data, myStruct);
        
        FAStoreEventManager.Register<int, Data, MyStruct>(StoreEventType.Buy, Buy);
        FAStoreEventManager.Trigger(StoreEventType.Buy, 2, data, myStruct);
        
        //原始调用，需要定义key的类型，
        //注意的是FAStoreEventManager是FAEventSingleManager<StoreEventType>的封装，
        //两个是同一个资源管理器
        FAEventSingleManager<StoreEventType>.Register<int, Data, MyStruct>(StoreEventType.Buy, Buy);
        FAEventSingleManager<StoreEventType>.Trigger(StoreEventType.Buy, 2, data, myStruct);
    }

    class Data
    {
    }

    struct MyStruct
    {
    }

    void Run(int index, string name, Data data, MyStruct myStruct)
    {
        //Debug.LogError($"Run=================={index} {name} {data} {myStruct}");
    }
    void Buy(int index, Data data, MyStruct myStruct)
    {
        //Debug.LogError($"Buy=================={index} {data} {myStruct}");
    }
    Data data = new Data();

    MyStruct myStruct = new MyStruct();

    // Update is called once per frame
    void Update()
    {
        Profiler.BeginSample("FAEventManager");
        for (int i = 0; i < 100000; i++)
        {
            // if (data==null)
            // {
            //     data = new Data();
            // }
            //Test(2, "test", data, myStruct);
            FAEventSingleManager<PubliceEventType>.Trigger(PubliceEventType.Run, 2, "test", data, myStruct);
        }
        
        Profiler.EndSample();
    }
}